Python: Allow branching from hosted Foundry conversations - #7526
Python: Allow branching from hosted Foundry conversations#7526Chinedum Echeta (cecheta) wants to merge 4 commits into
Conversation
Python Test Coverage Report •
Python Unit Test Overview
|
|||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Pull request overview
This PR updates the Python Foundry Hosting integration to support conversation branching by ensuring every Responses turn persists state under its immutable response_id, while conversations also maintain a conversation_id latest-state alias for continuation.
Changes:
- Persist regular-agent session snapshots under every
response_id, and additionally update theconversation_idsnapshot as a “latest turn” alias when a conversation is supplied. - For workflow agents, write checkpoints per-turn under
response_idand update aconversation_idcheckpoint alias to the latest checkpoint after each conversation turn. - Add/extend tests to validate branching behavior for both regular agents and workflow agents (streaming and non-streaming), and update Foundry Hosting docs to reflect the new persistence model.
Show a summary per file
| File | Description |
|---|---|
| python/packages/foundry_hosting/tests/test_responses.py | Adds branching-focused tests for both session snapshots and workflow checkpoints (including streaming). |
| python/packages/foundry_hosting/README.md | Documents the new model: always store under response_id plus a conversation_id latest-state alias. |
| python/packages/foundry_hosting/agent_framework_foundry_hosting/_session_store.py | Updates Foundry session store docstring to describe response-first storage plus conversation aliasing. |
| python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py | Implements response-id-first persistence for sessions and checkpoints; introduces workflow checkpoint finalization to update conversation aliases. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 1
- Review effort level: Lite
| # Each turn writes to response-addressed checkpoint storage. | ||
| # Conversation continuation is updated from its latest checkpoint | ||
| # after the run. | ||
| write_context_id = context.response_id |
There was a problem hiding this comment.
What happens if a conversation-backed workflow is cancelled or the client disconnects after the workflow has written a checkpoint? write_storage now points only at response_id, but _finalize_workflow_checkpoints is called only on the normal completion paths. Cancellation (CancelledError) and the failure handler therefore leave conversation_id at the previous turn. The next conversation request can restore stale state and repeat already-completed external side effects, so could we promote the latest response checkpoint during interruption or failure cleanup as well?
There was a problem hiding this comment.
The saving is in a finally block now, similar to when running a normal agent.
8aa377d to
e4d58cb
Compare
Motivation & Context
Allow branching from previous response in a conversation, by always storing state for response ID, plus conversation if applicable.
Description & Review Guide
State is now always stored under the response ID. If a conversation is supplied:
Related Issue
Fixes #7524
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.